import allure
from airtest.core.api import *

from common.airtest.airtest_base import AirtestBase, exists_1
from common.log.log import log
from config.conf import BASE_DIR
from po.jinhua.applets_po.my.points_details_page import PointsDetailsPage


class SignInEveryDayPage:
    """
    每日签到页
    """

    @allure.step('个人中心-每日打卡：立即签到')
    def sign_in_immediately(self):
        """
        个人中心-每日打卡：立即签到
        """
        try:
            log.info('个人中心-每日打卡：立即签到')
            element_1 = BASE_DIR + r"/element_picture/我的/每日签到/立即签到按钮.png"
            element_2 = BASE_DIR + r"/element_picture/我的/每日签到/已签到.png"
            element_3 = BASE_DIR + r"/element_picture/我的/每日签到/签到成功.png"
            if exists_1(element_1):
                AirtestBase().click_5(element_1)
                if exists_1(element_3):
                    log.info('签到成功！')
                    return True
                else:
                    log.info('签到失败！')
                    return False
            elif exists_1(element_2):
                log.info('今日已签到，不能再次签到！！')
                return True
        except Exception as e:
            log.error(f'个人中心-每日打卡：立即签到，过程中出现异常为：{e}')
            raise e

    @allure.step('个人中心-每日打卡：查看明细')
    def view_details(self):
        """
        个人中心-每日打卡：查看明细
        """
        try:
            log.info('个人中心-每日打卡：查看明细')
            element_1 = BASE_DIR + r"/element_picture/我的/每日签到/明细.png"
            AirtestBase().click_5(element_1)
            return PointsDetailsPage()
        except Exception as e:
            log.error(f'个人中心-每日打卡：查看明细，过程中出现异常为：{e}')
            raise e
